package com.ruoyi.web.controller.user;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.user.domain.VerifyCode;
import com.ruoyi.user.service.IVerifyCodeService;

/**
 * 手机短信验证码 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-14
 */
@Controller
@RequestMapping("/user/verifyCode")
public class VerifyCodeController extends BaseController
{
    private String prefix = "user/verifyCode";
	
	@Autowired
	private IVerifyCodeService verifyCodeService;
	
	@RequiresPermissions("user:verifyCode:view")
	@GetMapping()
	public String verifyCode()
	{
	    return prefix + "/verifyCode";
	}
	
	/**
	 * 查询手机短信验证码列表
	 */
	@RequiresPermissions("user:verifyCode:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(VerifyCode verifyCode)
	{
		startPage();
        List<VerifyCode> list = verifyCodeService.selectVerifyCodeList(verifyCode);
		return getDataTable(list);
	}
	
	/**
	 * 新增手机短信验证码
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存手机短信验证码
	 */
	@RequiresPermissions("user:verifyCode:add")
	@Log(title = "手机短信验证码", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(VerifyCode verifyCode)
	{		
		return toAjax(verifyCodeService.insertVerifyCode(verifyCode));
	}

	/**
	 * 修改手机短信验证码
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		VerifyCode verifyCode = verifyCodeService.selectVerifyCodeById(id);
		mmap.put("verifyCode", verifyCode);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存手机短信验证码
	 */
	@RequiresPermissions("user:verifyCode:edit")
	@Log(title = "手机短信验证码", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(VerifyCode verifyCode)
	{		
		return toAjax(verifyCodeService.updateVerifyCode(verifyCode));
	}
	
	/**
	 * 删除手机短信验证码
	 */
	@RequiresPermissions("user:verifyCode:remove")
	@Log(title = "手机短信验证码", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(verifyCodeService.deleteVerifyCodeByIds(ids));
	}
	
}
